<?php
/**
 * inlineRSS Plugin:  Allows inline RSS feeds from any source in any format (hopefully).
 *
 * Action plugin component, for cache validity determination
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Cal Demaine, Jan Wessely
 */
if(!defined('DOKU_INC')) die();  // no Dokuwiki, no go
 
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
 
class action_plugin_inlinerss extends DokuWiki_Action_Plugin {
 
    var $supportedModes = array('xhtml');
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Jan Wessely',
            'email'  => 'info@jawe.net',
            'date'   => '2007-03-03',
            'name'   => 'inlineRSS plugin (action plugin)',
            'desc'   => 'Allows inline RSS feeds from any source in any format',
            'url'    => 'http://jawe.net/wiki/proj/dokuwiki/plugins/inlinerss',
        );
    }
 
    /**
     * plugin should use this method to register its handlers with the dokuwiki's event controller
     */
    function register(&$controller) {
      $controller->register_hook('PARSER_CACHE_USE','BEFORE', $this, '_cache_prepare');
    }
 
    /**
     * prepare the cache object for default _useCache action
     */
    function _cache_prepare(&$event, $param) {
		global $ID;
		$cache =& $event->data;

		//error_log(__FILE__ . ":" . __LINE__ . ": cache mode " . $cache->mode);
 
		// we're only interested in wiki pages and supported render modes
		if (!isset($cache->page)) return;
		if (!isset($cache->mode) || !in_array($cache->mode, $this->supportedModes)) return;

		$hasPart = p_get_metadata($ID, 'relation haspart');
		//error_log(__FILE__ . ":" . __LINE__ . ": cache=" . print_r($cache, true));
		//error_log(__FILE__ . ":" . __LINE__ . ": hasPart=" . print_r($hasPart, true));
		$inlinerss = $this->loadHelper('inlinerss', 'Couldn\'t load the inlinerss helper plugin');
		foreach($hasPart as $name => $dummy) {
			$config = $inlinerss->loadConfig($name);
			//error_log(__FILE__ . ":" . __LINE__ . ": config=" . print_r($config, true));
			if ($config){
				$depends = $inlinerss->getDepends($config);
				// update depends['files'] array to include all included files
				$cache->depends['files'] = !empty($cache->depends['files']) ? array_merge($cache->depends['files'], $depends) : $depends;
			}
			//error_log(__FILE__ . ":" . __LINE__ . ": cache->depends['files'] = " . print_r($cache->depends['files'], true));
		}
    }
 
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :